<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="core" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
 <core:set var="date" value="<%=new Date() %>"/> 
<fmt:formatDate var ="today" value="${date }" type="date" pattern="yyyyMMdd"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<style>	.ui-autocomplete-loading { background: white url('/${initParam.context_root}/image/ui-anim_basic_16x16.gif') right center no-repeat; }
#autocomplete { width: 25em; }	</style>
<link type="text/css" href="/${initParam.context_root }/css/smoothness/jquery-ui-1.8.21.custom.css" rel="stylesheet" />
<script type="text/javascript" src="/${initParam.context_root }/jquery-1.7.2.min.js" ></script>
<script type="text/javascript" src="/${initParam.context_root }/jquery-ui-1.8.21.custom.min.js"></script>

<script type="text/javascript">
	$(document).ready(function(){	
		$("#useEndDate").change(function(){
			var today = ${today};
			var useEndDate = $(this).val();
			
			var endDate = useEndDate.substring(0,4)+useEndDate.substring(6,8)+useEndDate.substring(10,12);
			var compareDate = window.parseInt(endDate);
			var compareToday = window.parseInt(today);
			
			if(compareDate < compareToday ){
				$("#couponMessage").html("<font color='red'>사용기간이 지난 쿠폰은 등록할 수 없습니다.</font>");
			} else{
				$("#couponMessage").html("<font color='green'></font>");
			}
		});
		
		$.datepicker.setDefaults($.datepicker.regional["ko"]);
		
		$("#useStartDate").datepicker($.datepicker.regional[ "ko" ]);
// 		$("#useStartDate").datepicker();
		$("#useStartDate").datepicker("option", "dateFormat", "yy년 mm월 dd일");
		
		$("#useEndDate").datepicker($.datepicker.regional[ "ko" ]);
// 		$("#useEndDate").datepicker();
		$("#useEndDate").datepicker("option", "dateFormat", "yy년 mm월 dd일");
		
		
		$("input[name=originalPrice]").keyup(function(){
			
			if(!$.isNumeric($(this).val()) ){
				$("#originalPrice").html("<font color='red'>숫자만 입력 가능합니다..</font>");
			} else{
				$("#originalPrice").html("");
			}
		});
		$("input[name=couponPrice]").keyup(function(){
			if(!$.isNumeric($(this).val()) ){
				$("#couponPrice").html("<font color='red'>숫자만 입력 가능합니다..</font>");
			} else{
				$("#couponPrice").html("");
			}
		});
		$("input[name=wantPrice]").keyup(function(){
			if(!$.isNumeric($(this).val()) ){
				$("#wantPrice").html("<font color='red'>숫자만 입력 가능합니다..</font>");
			} else{
				$("#wantPrice").html("");
			}
		});
		
		
		$("#submitBtn").click(function(){
			$("#auctionRegister").attr("action", "/${initParam.context_root }/registerAuction.do");
			$("#auctionRegister").attr("method", "POST");
			$("#auctionRegister").attr("enctype","multipart/form-data");
			
			if(!$("#auctionName").val()){
				alert("이름을 입력하세요.");
				return false;
			} else if(!$("#productName").val()){
				alert("상품명을 입력하세요.");
				return false;
			} else if(!$("input[name=originalPrice]").val()){
				alert("정상가를 입력하세요.");
				return false;
			} else if(!$.isNumeric($("input[name=originalPrice]").val()) ){
				alert("숫자를 입력하세요.");
				return false;
			}
			else if(!$("input[name=couponPrice]").val()){
				alert("구입가를 입력하세요.");
				return false;
			} else if(!$.isNumeric($("input[name=couponPrice]").val()) ){
				alert("숫자를 입력하세요.");
				return false;
			}  else if(!$("input[name=wantPrice]").val()){
				alert("희망가를 입력하세요.");
				return false;
			} else if(!$.isNumeric($("input[name=wantPrice]").val()) ){
				alert("숫자를 입력하세요.");
				return false;
			} else if($("select[name=saleLocation]").val() == "default"){
				alert("판매지역을 선택하세요.");
				return false;
			} else if($("select[name=category_name]").val() == "default"){
				alert("카테고리를 선택하세요.");
				return false; 
			} else if(!$("textarea[name=auctionContent]").val()){
				alert("상세 설명을 입력하세요.");
				return false; 
			} 
			
			$("#auctionRegister").submit();
		});
		
	});
</script>
<form id="auctionRegister">
<table>
	<tr>
		<td>제목</td>
		<td><input type="text" id="auctionName" name ="auctionName"></td>
	</tr>
	<tr>
		<td>상품명</td>
		<td><input type="text" id="productName" name ="productName"></td>
	</tr>
	<tr>
		<td>상품 URL</td>
		<td><input type="text" id="sellSite" name ="sellSite"></td>
	</tr>
	<tr>
		<td>상품이미지</td>
		<td><input type="file" name="upfile"></td>
	</tr>
	<tr>
		<td>쿠폰 사용기간</td>
		<td><input type="text" name="useStartDate" id="useStartDate" readonly="readonly"> ~ <input type="text" name="useEndDate" id="useEndDate" readonly="readonly">&nbsp;<span id = "couponMessage"></span></td>
	</tr>
	<tr>
		<td>정상가</td>
		<td><input type="text" name="originalPrice">원 <span id="originalPrice"></span></td>
	</tr>
	<tr>
		<td>구입가</td>
		<td><input type="text" name="couponPrice">원 <span id="couponPrice"></span></td>
	</tr>
	<tr>
		<td>희망 판매가</td>
		<td><input type="text" name="wantPrice">원 <span id="wantPrice"></span></td>
	</tr>
	<tr>
		<td>지역</td>
		<td><select name="saleLocation">
			<option value="default">지역선택</option>
			<core:forEach items="${requestScope.location }" var="loc">
			<option value="${loc }">${loc}</option>
			</core:forEach>
		</select>
		</td>
	</tr>
	<tr>
		<td>카테고리</td>
		<td><select name="categoryName">
		<option value="default">선택</option>
		<core:forEach items="${requestScope.category }" var="cat">
			<option value="${cat }">${cat }</option>
		</core:forEach>
		</select></td>
	</tr>
	<tr>
		<td>상세 설명</td>
		<td><textarea name="auctionContent" rows="10" cols="80"></textarea></td>
	</tr>
	<tfoot>
	<tr>
		<td colspan="2"><input type="button" value="중고등록" id="submitBtn"> <input type="reset" value="취소"></td>
	</tr>
	</tfoot>
</table>
</form>
